package thread.thread_5_8.test_count_own;

import java.util.concurrent.CountDownLatch;

/**
 * @author bruin_du
 * @description 使用计数器
 * @date 2022/5/8 10:33
 **/
public class Main {
    // count: 计数器为 3 个，只有 3 个全部报到了，门闩才会打开
    static CountDownLatch countDownLatch = new CountDownLatch(3);


    static class MyThread extends Thread {
        @Override
        public void run() {
            countDownLatch.countDown();
            countDownLatch.countDown();
            countDownLatch.countDown();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread t = new MyThread();
        t.start();

        countDownLatch.await();

        System.out.println("门闩被打开了");
    }
}